﻿@using WeiXinMongoApis.Controllers

@{
    ViewBag.Title = "爆文助手报表";
}

<h5>统计时间：@ViewBag.MinDate.ToString("yyyy年MM月dd日") ～@DateTime.Now.ToString("yyyy年MM月dd日")</h5>
<br><b>用户登录日志</b>
<table class="imagetable">
    <tr>
        @{
            List<List<TrialUser>> usersList = ViewBag.UsersList as List<List<TrialUser>>;
            List<LoginUser> loginUsers = ViewBag.LoginUsers as List<LoginUser>;
            int totalUsers = 0;

            <th>昨日新用户</th>
            <th>今日新用户</th>

            <th>昨日登录人次</th>
            <th>今日登录人次</th>
            <th>历史合计登录人次</th>
        }
    </tr>
    <tr>
        @{
            <td>@ViewBag.LastdayTrialUsersCount</td>
            <td>@ViewBag.TodayTrialUsersCount</td>
            <td>@ViewBag.LastdayLoginCount</td>
            <td>@ViewBag.TodayLoginCount</td>
            <td>@ViewBag.LoginCountAll</td>
        }
    </tr>
</table>
<br><b>新用户统计</b>
<table class="imagetable">
    <tr>
        @for (int i = 0; i < usersList.Count; i++)
        {
            List<TrialUser> users = usersList[i];

            <th> @users[0].StartDate.ToString("yyyy年MM月")</th>
            totalUsers += @users.Count;
        }
        <th>合计用户数</th>
    </tr>
    <tr>
        @for (int i = 0; i < usersList.Count; i++)
        {
            List<TrialUser> users = usersList[i];

            <td>@users.Count 位新用户</td>
            totalUsers += @users.Count;
        }
        <td>@totalUsers</td>
    </tr>
</table>

<br><b>今日登录日志</b>
<table class="imagetable">
    <tr>
        <th>客户端识别码</th>
        <th>登录时间</th>
        <th>IP地址</th>
        <th width="100px">操作系统版本</th>
        <th>Clickonce安装目录</th>
        <th>机器名</th>
        <th>登录用户名</th>
        <th>Mac地址</th>
        <th>硬盘ID</th>
        <th>主板ID</th>
    </tr>

    @{

        foreach (LoginUser item in loginUsers.Where(r => r.LoginTime.Date == DateTime.Now.Date))
        {
            <tr>
                <td>@item.ClientId</td>
                <td>@item.LoginTime</td>
                <td>@item.IpAddress</td>
                <td>@item.OsVersion</td>
                <td><a href="#" onclick="alert('@item.CurrentDirectory')">查看</a> </td>
                <td>@item.MachineName</td>
                <td>@item.UserName</td>
                <td>@item.MacAddress</td>
                <td>@item.HardID</td>
                <td>@item.Motherboard</td>
            </tr>
        }
    }


</table>

<br><b>所有登录</b>
@{
    DateTime start = loginUsers.Min(r => r.LoginTime);
    DateTime end = loginUsers.Max(r => r.LoginTime);
    DateTime startTemp = start;
    DateTime startTemp2 = start;

}
@*@{
    DateTime startTime = DateTime.Now;
}
<table class="imagetable">
    <tr>
        <th>No</th>
        <th>识别码</th>
        @while (startTemp <= end)
        {
            <th>@startTemp.ToString("M.d")</th>
            startTemp = startTemp.AddDays(1);
        }
    </tr>

    @{
        List<string> calculatedUsers = new List<string>();
        int number = 0;
        foreach (LoginUser item in loginUsers)
        {
           
            number = number + 1;
            if (calculatedUsers.Contains(item.ClientId))
            {
                continue;
            }
            calculatedUsers.Add(item.ClientId);
            <tr>
                <td>@number</td>
                <td>@item.ClientId</td>
                @{DateTime s = start;}
                @while (s <= end)
                {
                    <td>
                        @{
                        var current = loginUsers.Where(r => r.ClientId == item.ClientId);
                        var currentMinDate = current.Min(r => r.LoginTime);
                        string mark = "";
                       
                        if (s.Date < currentMinDate.Date)
                        {
                            mark = "";
                        }
                        else if (s.Date == currentMinDate.Date)
	                    {
                            mark = "★★";
	                    }
                        else
                        {
                            mark = current.Any(r => r.LoginTime.Date == s.Date) == false ? "×" : "●";
                        }
                        <b>@mark</b>
                        }
                    </td>
                        s = s.AddDays(1);
                }
            </tr>
        }
    }


</table>
<h3>开始时间:@startTime</h3>
<h3>结束时间:@DateTime.Now</h3>*@
<style type="text/css">
    table.imagetable {
        font-family: verdana,arial,sans-serif;
        font-size: 11px;
        color: #333333;
        border-width: 1px;
        border-color: #999999;
        border-collapse: collapse;
    }

        table.imagetable th {
            background: #b5cfd2 url('cell-blue.jpg');
            border-width: 1px;
            padding: 8px;
            border-style: solid;
            border-color: #999999;
        }

        table.imagetable td {
            background: #dcddc0 url('cell-grey.jpg');
            border-width: 1px;
            padding: 8px;
            border-style: solid;
            border-color: #999999;
        }
</style>